package com.example.demo.entity;

import java.util.ArrayList;
import java.util.List;

/**
 * @program:IntelliJ IDEA
 * @Description:员工类
 * @author:Mr.CheCheHuiBujianO
 * @data: 2023/3/9 19:18
 */
public class Staff {
    private String staffName; //职工姓名
    private String staffPerference;//职工偏好
    public Gene gene;//用于记录该员工基因

    public String getStaffName() {
        return staffName;
    }

    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }

    public String getStaffPerference() {
        return staffPerference;
    }

    public void setStaffPerference(String staffPerference) {
        this.staffPerference = staffPerference;
    }


    private List<ArrayList<Integer>> staffPerferenceDecode; //用于解码staffPerference



    public Staff(String staffName, String staffPerference) {


        this.staffName = staffName;
        this.staffPerference = staffPerference;
        this.gene = new Gene();


        if (staffPerference != null) {

            staffPerferenceDecode = new ArrayList<>(3);
            for (int i = 0; i < 3; i++) {
                staffPerferenceDecode.add(new ArrayList<>());
            }
            ArrayList<Integer> decode = helpDecode(this.staffPerference);
        /*
        解码操作 将员工偏好进行翻译 staffPerferenceDecode的下标0.日常工作时间
                            1.上班时间段偏好 2.上班日偏好
         */
            if (decode.size() == 1) {
                staffPerferenceDecode.set(0, decode);
            }
            if (decode.size() == 26) {
                staffPerferenceDecode.set(1, decode);
            }
            if (decode.size() == 7) {
                staffPerferenceDecode.set(2, decode);
            }
        }
    }


    /**
     * @Description:帮助解码操作 去切分字符出分别 1.日常工作时间
     * 2.上班时间段偏好
     * 3.上班日偏好
     * @Param: [staffPerference]
     * @return:java.util.ArrayList<java.lang.Integer>
     * @Author: Mr.Lin
     * @Date: 2023/3/9 21:23
     */
    private ArrayList<Integer> helpDecode(String staffPerference) {
        //输入格式应该位日工作时长？点 所以找下标位置为5的数值
        if (staffPerference.contains("日工作时长")) {
            Integer DayWorkTime = Integer.valueOf(staffPerference.charAt(5) - 48);
            ArrayList<Integer> DayWorkTimeRes = new ArrayList<>();
            return DayWorkTimeRes;
        }
        if (staffPerference.contains("上班时间偏好")) {
            staffPerference = staffPerference.substring(6);
            String[] workingHours = staffPerference.split("到");
            int begin = Integer.valueOf(workingHours[0]);
            int end = Integer.valueOf(workingHours[1]);
            int[] tmp = new int[26];
            //时间转换 因为上班时长只有12个小时半个小时一班 从9点开始到10点（包括周末）所以工作时间段长度应该为26
            begin = begin * 2 - 18;
            end = end * 2 - 18;
            for (int i = begin; i < end; i++) {
                tmp[i] = 1;
            }
            ArrayList<Integer> workingHoursArr = new ArrayList<>();
            for (int i = 0; i < tmp.length; i++) {
                workingHoursArr.add(tmp[i]);
            }
            return workingHoursArr;
        }
        if (staffPerference.contains("工作日偏好")) {
            staffPerference = staffPerference.substring(5);
            String[] workDays = staffPerference.split("、");
            int[] tmp = new int[7];
            for (int i = 0; i < workDays.length; i++) {
                tmp[Integer.valueOf(workDays[i])]++;
            }
            ArrayList<Integer> workDaysArr = new ArrayList<>();
            for (int i = 0; i < tmp.length; i++) {
                workDaysArr.add(tmp[i]);
            }
            return workDaysArr;
        }
        return null;
    }
}
